package com.lb.jwitter.action;


import java.util.ArrayList; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 

import com.lb.jwitter.service.TblQLDTTXAHocVienTamDungHocKy;
import com.lb.jwitter.service.TblQLDTTXAHocVienTamDungHocKyService;
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAHocVien;
import com.lb.jwitter.service.TblQLDTTXAHocVienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVienSearchAction{
    private int pageSize; 
    public void setPageSize(int pageSize) {
       this.pageSize = pageSize;
     }

    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public void setPage(int page) { this.page = page;   }

    public int getPage() {
       return page;
   }

    private int pages; 
    public void setPages(int pages) { this.pages = pages;   }

    public int getPages() {
       return pages;
     }

    private String dataString; 
    public void setDataString(String dataString) { this.dataString = dataString;    }

    public String getDataString() {
       return dataString;
    }

    private Message msg; 
    public Message getMsg() { return msg; }

    private String mSHV; 
    public void setMSHV(String mSHV) {
       this.mSHV = mSHV;
   }

    public String getMSHV() {
       return mSHV;
   }

    private String hoTen; 
    public void setHoTen(String hoTen) {
       this.hoTen = hoTen;
   }

    public String getHoTen() {
       return hoTen;
   }
    
    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
   }

    public String getTen() {
       return ten;
   }

    private int lopId; 
    public void setLopId(int lopId) {
       this.lopId = lopId;
  }

    public int getLopId() {
       return lopId;
  }

    private int nganhId; 
    public void setNganhId(int nganhId) {
       this.nganhId = nganhId;
  }

    public int getNganhId() {
       return nganhId;
  }

    private int khoaId; 
    public void setKhoaId(int khoaId) {
       this.khoaId = khoaId;
  }

    public int getKhoaId() {
       return khoaId;
  }
    
    private int trangThaiId;
    

	
	public int getTrangThaiId() {
		return trangThaiId;
	}

	public void setTrangThaiId(int trangThaiId) {
		this.trangThaiId = trangThaiId;
	}

	private List<TblQLDTTXAHocVien> tblQLDTTXAHocViens; 
    public List<TblQLDTTXAHocVien>  getTblQLDTTXAHocViens() {
        return tblQLDTTXAHocViens; 
      } 
    
    
	private TblQLDTTXAHocVienService tblQLDTTXAHocVienService; 
    
    private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien", "xem")){ 
        return "noprivilege"; 
    }        tblQLDTTXAHocVienService = (TblQLDTTXAHocVienService) context.getBean("tbl_QLDTTXA_HocVienClient");
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
        
    
            
    cons.clear();
    if(mSHV != null && !mSHV.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("MSHV");
        con.setValue1("%" + mSHV + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(hoTen != null && !hoTen.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hoTen");
        con.setValue1("%" + hoTen + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(ten != null && !ten.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("ten");
        con.setValue1("%" + ten + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(lopId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("lopId.id");
        con.setValue1(new Long(lopId));
        con.setOperator("eq");
        cons.add(con);	
    }     
    if(nganhId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("nganhId.id");
        con.setValue1(new Long(nganhId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(khoaId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("khoaId.id");
        con.setValue1(new Long(khoaId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(trangThaiId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("trangThaiId.id");
        con.setValue1(new Long(trangThaiId));
        con.setOperator("eq");
        cons.add(con);	
    } 
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSize == 0){ 
               pageSize = 20; 
           } 
            if(page == 0){ 
               page =1; 
           } 
           tblQLDTTXAHocViens = tblQLDTTXAHocVienService.findtblQLDTTXAHocVienByCondition(cons,pageSize,page); 
           pages = tblQLDTTXAHocVienService.counttblQLDTTXAHocVienByCondition(cons)/pageSize + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataString = ""; 
      dataString += "&mSHV=" + mSHV; 
      dataString += "&hoTen=" + hoTen; 
      dataString += "&ten=" + ten; 
      dataString += "&lopId=" + lopId; 
      dataString += "&nganhId=" + nganhId; 
      dataString += "&khoaId=" + khoaId; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_QLDTTXA_HocVien Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
